﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using PAT.Entities;
using PAT.Data;

#endregion

namespace PAT.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="PatItemListaPreciosProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class PatItemListaPreciosProviderBaseCore : EntityProviderBase<PAT.Entities.PatItemListaPrecios, PAT.Entities.PatItemListaPreciosKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByIdItemInventarioFromPatItemInventarioListaPrecios
		
		/// <summary>
		///		Gets PAT_ITEM_LISTA_PRECIOS objects from the datasource by ID_ITEM_INVENTARIO in the
		///		PAT_ITEM_INVENTARIO_LISTA_PRECIOS table. Table PAT_ITEM_LISTA_PRECIOS is related to table PAT_ITEM_INVENTARIO
		///		through the (M:N) relationship defined in the PAT_ITEM_INVENTARIO_LISTA_PRECIOS table.
		/// </summary>
		/// <param name="_idItemInventario"></param>
		/// <returns>Returns a typed collection of PatItemListaPrecios objects.</returns>
		public TList<PatItemListaPrecios> GetByIdItemInventarioFromPatItemInventarioListaPrecios(System.Int32 _idItemInventario)
		{
			int count = -1;
			return GetByIdItemInventarioFromPatItemInventarioListaPrecios(null,_idItemInventario, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets PAT.Entities.PatItemListaPrecios objects from the datasource by ID_ITEM_INVENTARIO in the
		///		PAT_ITEM_INVENTARIO_LISTA_PRECIOS table. Table PAT_ITEM_LISTA_PRECIOS is related to table PAT_ITEM_INVENTARIO
		///		through the (M:N) relationship defined in the PAT_ITEM_INVENTARIO_LISTA_PRECIOS table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_idItemInventario"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of PatItemListaPrecios objects.</returns>
		public TList<PatItemListaPrecios> GetByIdItemInventarioFromPatItemInventarioListaPrecios(System.Int32 _idItemInventario, int start, int pageLength)
		{
			int count = -1;
			return GetByIdItemInventarioFromPatItemInventarioListaPrecios(null, _idItemInventario, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets PatItemListaPrecios objects from the datasource by ID_ITEM_INVENTARIO in the
		///		PAT_ITEM_INVENTARIO_LISTA_PRECIOS table. Table PAT_ITEM_LISTA_PRECIOS is related to table PAT_ITEM_INVENTARIO
		///		through the (M:N) relationship defined in the PAT_ITEM_INVENTARIO_LISTA_PRECIOS table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idItemInventario"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of PAT_ITEM_LISTA_PRECIOS objects.</returns>
		public TList<PatItemListaPrecios> GetByIdItemInventarioFromPatItemInventarioListaPrecios(TransactionManager transactionManager, System.Int32 _idItemInventario)
		{
			int count = -1;
			return GetByIdItemInventarioFromPatItemInventarioListaPrecios(transactionManager, _idItemInventario, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets PatItemListaPrecios objects from the datasource by ID_ITEM_INVENTARIO in the
		///		PAT_ITEM_INVENTARIO_LISTA_PRECIOS table. Table PAT_ITEM_LISTA_PRECIOS is related to table PAT_ITEM_INVENTARIO
		///		through the (M:N) relationship defined in the PAT_ITEM_INVENTARIO_LISTA_PRECIOS table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idItemInventario"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of PAT_ITEM_LISTA_PRECIOS objects.</returns>
		public TList<PatItemListaPrecios> GetByIdItemInventarioFromPatItemInventarioListaPrecios(TransactionManager transactionManager, System.Int32 _idItemInventario,int start, int pageLength)
		{
			int count = -1;
			return GetByIdItemInventarioFromPatItemInventarioListaPrecios(transactionManager, _idItemInventario, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets PatItemListaPrecios objects from the datasource by ID_ITEM_INVENTARIO in the
		///		PAT_ITEM_INVENTARIO_LISTA_PRECIOS table. Table PAT_ITEM_LISTA_PRECIOS is related to table PAT_ITEM_INVENTARIO
		///		through the (M:N) relationship defined in the PAT_ITEM_INVENTARIO_LISTA_PRECIOS table.
		/// </summary>
		/// <param name="_idItemInventario"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of PAT_ITEM_LISTA_PRECIOS objects.</returns>
		public TList<PatItemListaPrecios> GetByIdItemInventarioFromPatItemInventarioListaPrecios(System.Int32 _idItemInventario,int start, int pageLength, out int count)
		{
			
			return GetByIdItemInventarioFromPatItemInventarioListaPrecios(null, _idItemInventario, start, pageLength, out count);
		}


		/// <summary>
		///		Gets PAT_ITEM_LISTA_PRECIOS objects from the datasource by ID_ITEM_INVENTARIO in the
		///		PAT_ITEM_INVENTARIO_LISTA_PRECIOS table. Table PAT_ITEM_LISTA_PRECIOS is related to table PAT_ITEM_INVENTARIO
		///		through the (M:N) relationship defined in the PAT_ITEM_INVENTARIO_LISTA_PRECIOS table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_idItemInventario"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of PatItemListaPrecios objects.</returns>
		public abstract TList<PatItemListaPrecios> GetByIdItemInventarioFromPatItemInventarioListaPrecios(TransactionManager transactionManager,System.Int32 _idItemInventario, int start, int pageLength, out int count);
		
		#endregion GetByIdItemInventarioFromPatItemInventarioListaPrecios
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, PAT.Entities.PatItemListaPreciosKey key)
		{
			return Delete(transactionManager, key.IdItemListaPrecio);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_idItemListaPrecio">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Byte _idItemListaPrecio)
		{
			return Delete(null, _idItemListaPrecio);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idItemListaPrecio">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Byte _idItemListaPrecio);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override PAT.Entities.PatItemListaPrecios Get(TransactionManager transactionManager, PAT.Entities.PatItemListaPreciosKey key, int start, int pageLength)
		{
			return GetByIdItemListaPrecio(transactionManager, key.IdItemListaPrecio, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_PAT_ITEM_LISTA_PRECIOS index.
		/// </summary>
		/// <param name="_idItemListaPrecio"></param>
		/// <returns>Returns an instance of the <see cref="PAT.Entities.PatItemListaPrecios"/> class.</returns>
		public PAT.Entities.PatItemListaPrecios GetByIdItemListaPrecio(System.Byte _idItemListaPrecio)
		{
			int count = -1;
			return GetByIdItemListaPrecio(null,_idItemListaPrecio, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_PAT_ITEM_LISTA_PRECIOS index.
		/// </summary>
		/// <param name="_idItemListaPrecio"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="PAT.Entities.PatItemListaPrecios"/> class.</returns>
		public PAT.Entities.PatItemListaPrecios GetByIdItemListaPrecio(System.Byte _idItemListaPrecio, int start, int pageLength)
		{
			int count = -1;
			return GetByIdItemListaPrecio(null, _idItemListaPrecio, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_PAT_ITEM_LISTA_PRECIOS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idItemListaPrecio"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="PAT.Entities.PatItemListaPrecios"/> class.</returns>
		public PAT.Entities.PatItemListaPrecios GetByIdItemListaPrecio(TransactionManager transactionManager, System.Byte _idItemListaPrecio)
		{
			int count = -1;
			return GetByIdItemListaPrecio(transactionManager, _idItemListaPrecio, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_PAT_ITEM_LISTA_PRECIOS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idItemListaPrecio"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="PAT.Entities.PatItemListaPrecios"/> class.</returns>
		public PAT.Entities.PatItemListaPrecios GetByIdItemListaPrecio(TransactionManager transactionManager, System.Byte _idItemListaPrecio, int start, int pageLength)
		{
			int count = -1;
			return GetByIdItemListaPrecio(transactionManager, _idItemListaPrecio, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_PAT_ITEM_LISTA_PRECIOS index.
		/// </summary>
		/// <param name="_idItemListaPrecio"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="PAT.Entities.PatItemListaPrecios"/> class.</returns>
		public PAT.Entities.PatItemListaPrecios GetByIdItemListaPrecio(System.Byte _idItemListaPrecio, int start, int pageLength, out int count)
		{
			return GetByIdItemListaPrecio(null, _idItemListaPrecio, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_PAT_ITEM_LISTA_PRECIOS index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_idItemListaPrecio"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="PAT.Entities.PatItemListaPrecios"/> class.</returns>
		public abstract PAT.Entities.PatItemListaPrecios GetByIdItemListaPrecio(TransactionManager transactionManager, System.Byte _idItemListaPrecio, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;PatItemListaPrecios&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;PatItemListaPrecios&gt;"/></returns>
		public static TList<PatItemListaPrecios> Fill(IDataReader reader, TList<PatItemListaPrecios> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				PAT.Entities.PatItemListaPrecios c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("PatItemListaPrecios")
					.Append("|").Append((System.Byte)reader[((int)PatItemListaPreciosColumn.IdItemListaPrecio - 1)]).ToString();
					c = EntityManager.LocateOrCreate<PatItemListaPrecios>(
					key.ToString(), // EntityTrackingKey
					"PatItemListaPrecios",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new PAT.Entities.PatItemListaPrecios();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.IdItemListaPrecio = (System.Byte)reader[((int)PatItemListaPreciosColumn.IdItemListaPrecio - 1)];
					c.Descripcion = (System.String)reader[((int)PatItemListaPreciosColumn.Descripcion - 1)];
					c.Activo = (System.Boolean)reader[((int)PatItemListaPreciosColumn.Activo - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="PAT.Entities.PatItemListaPrecios"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="PAT.Entities.PatItemListaPrecios"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, PAT.Entities.PatItemListaPrecios entity)
		{
			if (!reader.Read()) return;
			
			entity.IdItemListaPrecio = (System.Byte)reader[((int)PatItemListaPreciosColumn.IdItemListaPrecio - 1)];
			entity.Descripcion = (System.String)reader[((int)PatItemListaPreciosColumn.Descripcion - 1)];
			entity.Activo = (System.Boolean)reader[((int)PatItemListaPreciosColumn.Activo - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="PAT.Entities.PatItemListaPrecios"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="PAT.Entities.PatItemListaPrecios"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, PAT.Entities.PatItemListaPrecios entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IdItemListaPrecio = (System.Byte)dataRow["ID_ITEM_LISTA_PRECIO"];
			entity.Descripcion = (System.String)dataRow["DESCRIPCION"];
			entity.Activo = (System.Boolean)dataRow["ACTIVO"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="PAT.Entities.PatItemListaPrecios"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">PAT.Entities.PatItemListaPrecios Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, PAT.Entities.PatItemListaPrecios entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByIdItemListaPrecio methods when available
			
			#region IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<PatItemInventario>|IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios", deepLoadType, innerList))
			{
				entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios = DataRepository.PatItemInventarioProvider.GetByIdListaPreciosItemFromPatItemInventarioListaPrecios(transactionManager, entity.IdItemListaPrecio);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios != null)
				{
					deepHandles.Add("IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< PatItemInventario >) DataRepository.PatItemInventarioProvider.DeepLoad,
						new object[] { transactionManager, entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region PatItemInventarioListaPreciosCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PatItemInventarioListaPrecios>|PatItemInventarioListaPreciosCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PatItemInventarioListaPreciosCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PatItemInventarioListaPreciosCollection = DataRepository.PatItemInventarioListaPreciosProvider.GetByIdListaPreciosItem(transactionManager, entity.IdItemListaPrecio);

				if (deep && entity.PatItemInventarioListaPreciosCollection.Count > 0)
				{
					deepHandles.Add("PatItemInventarioListaPreciosCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PatItemInventarioListaPrecios>) DataRepository.PatItemInventarioListaPreciosProvider.DeepLoad,
						new object[] { transactionManager, entity.PatItemInventarioListaPreciosCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PatTransferenciaCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PatTransferencia>|PatTransferenciaCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PatTransferenciaCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PatTransferenciaCollection = DataRepository.PatTransferenciaProvider.GetByIdItemListaPrecio(transactionManager, entity.IdItemListaPrecio);

				if (deep && entity.PatTransferenciaCollection.Count > 0)
				{
					deepHandles.Add("PatTransferenciaCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PatTransferencia>) DataRepository.PatTransferenciaProvider.DeepLoad,
						new object[] { transactionManager, entity.PatTransferenciaCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the PAT.Entities.PatItemListaPrecios object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">PAT.Entities.PatItemListaPrecios instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">PAT.Entities.PatItemListaPrecios Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, PAT.Entities.PatItemListaPrecios entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();

			#region IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios>
			if (CanDeepSave(entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios, "List<PatItemInventario>|IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios", deepSaveType, innerList))
			{
				if (entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios.Count > 0 || entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios.DeletedItems.Count > 0)
				{
					DataRepository.PatItemInventarioProvider.Save(transactionManager, entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios); 
					deepHandles.Add("IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<PatItemInventario>) DataRepository.PatItemInventarioProvider.DeepSave,
						new object[] { transactionManager, entity.IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 
	
			#region List<PatItemInventarioListaPrecios>
				if (CanDeepSave(entity.PatItemInventarioListaPreciosCollection, "List<PatItemInventarioListaPrecios>|PatItemInventarioListaPreciosCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PatItemInventarioListaPrecios child in entity.PatItemInventarioListaPreciosCollection)
					{
						if(child.IdListaPreciosItemSource != null)
						{
								child.IdListaPreciosItem = child.IdListaPreciosItemSource.IdItemListaPrecio;
						}

						if(child.IdItemInventarioSource != null)
						{
								child.IdItemInventario = child.IdItemInventarioSource.IdItemInventario;
						}

					}

					if (entity.PatItemInventarioListaPreciosCollection.Count > 0 || entity.PatItemInventarioListaPreciosCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PatItemInventarioListaPreciosProvider.Save(transactionManager, entity.PatItemInventarioListaPreciosCollection);
						
						deepHandles.Add("PatItemInventarioListaPreciosCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PatItemInventarioListaPrecios >) DataRepository.PatItemInventarioListaPreciosProvider.DeepSave,
							new object[] { transactionManager, entity.PatItemInventarioListaPreciosCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PatTransferencia>
				if (CanDeepSave(entity.PatTransferenciaCollection, "List<PatTransferencia>|PatTransferenciaCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PatTransferencia child in entity.PatTransferenciaCollection)
					{
						if(child.IdItemListaPrecioSource != null)
						{
							child.IdItemListaPrecio = child.IdItemListaPrecioSource.IdItemListaPrecio;
						}
						else
						{
							child.IdItemListaPrecio = entity.IdItemListaPrecio;
						}

					}

					if (entity.PatTransferenciaCollection.Count > 0 || entity.PatTransferenciaCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PatTransferenciaProvider.Save(transactionManager, entity.PatTransferenciaCollection);
						
						deepHandles.Add("PatTransferenciaCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PatTransferencia >) DataRepository.PatTransferenciaProvider.DeepSave,
							new object[] { transactionManager, entity.PatTransferenciaCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region PatItemListaPreciosChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>PAT.Entities.PatItemListaPrecios</c>
	///</summary>
	public enum PatItemListaPreciosChildEntityTypes
	{

		///<summary>
		/// Collection of <c>PatItemListaPrecios</c> as ManyToMany for PatItemInventarioCollection_From_PatItemInventarioListaPrecios
		///</summary>
		[ChildEntityType(typeof(TList<PatItemInventario>))]
		IdItemInventarioPatItemInventarioCollection_From_PatItemInventarioListaPrecios,

		///<summary>
		/// Collection of <c>PatItemListaPrecios</c> as OneToMany for PatItemInventarioListaPreciosCollection
		///</summary>
		[ChildEntityType(typeof(TList<PatItemInventarioListaPrecios>))]
		PatItemInventarioListaPreciosCollection,

		///<summary>
		/// Collection of <c>PatItemListaPrecios</c> as OneToMany for PatTransferenciaCollection
		///</summary>
		[ChildEntityType(typeof(TList<PatTransferencia>))]
		PatTransferenciaCollection,
	}
	
	#endregion PatItemListaPreciosChildEntityTypes
	
	#region PatItemListaPreciosFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;PatItemListaPreciosColumn&gt;"/> class
	/// that is used exclusively with a <see cref="PatItemListaPrecios"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class PatItemListaPreciosFilterBuilder : SqlFilterBuilder<PatItemListaPreciosColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PatItemListaPreciosFilterBuilder class.
		/// </summary>
		public PatItemListaPreciosFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the PatItemListaPreciosFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public PatItemListaPreciosFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the PatItemListaPreciosFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public PatItemListaPreciosFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion PatItemListaPreciosFilterBuilder
	
	#region PatItemListaPreciosParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;PatItemListaPreciosColumn&gt;"/> class
	/// that is used exclusively with a <see cref="PatItemListaPrecios"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class PatItemListaPreciosParameterBuilder : ParameterizedSqlFilterBuilder<PatItemListaPreciosColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PatItemListaPreciosParameterBuilder class.
		/// </summary>
		public PatItemListaPreciosParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the PatItemListaPreciosParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public PatItemListaPreciosParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the PatItemListaPreciosParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public PatItemListaPreciosParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion PatItemListaPreciosParameterBuilder
	
	#region PatItemListaPreciosSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;PatItemListaPreciosColumn&gt;"/> class
	/// that is used exclusively with a <see cref="PatItemListaPrecios"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class PatItemListaPreciosSortBuilder : SqlSortBuilder<PatItemListaPreciosColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PatItemListaPreciosSqlSortBuilder class.
		/// </summary>
		public PatItemListaPreciosSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion PatItemListaPreciosSortBuilder
	
} // end namespace
